package cuiyt.leetcode.other;

/**
 * @author cyt
 * @create 2020-07-31 20:45
 */
public class T0803 {

    public static void main(String[] args) {

    }


    public int findMagicIndex(int[] nums) {
        int flag = 0;
        int a = 0;
        int  k = 0;
        int[] b = new int [nums.length];
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] == a++) {
                flag = 1;
                b[k++] = nums[i];
            }
        }
        if(flag==0){
            return -1;
        }else{
            return b[0];
        }

    }
}
